<template>
<el-form ref="form" :model="form" label-width="80px">
  <el-form-item label="用户名">
    <el-input v-model="form.name"></el-input>
  </el-form-item>
  <el-form-item label="邮箱">
    <el-input v-model="form.email"></el-input>
  </el-form-item>
  <el-form-item label="密码">
    <el-input v-model="form.password"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="onSubmit">立即创建</el-button>
    <el-button>取消</el-button>
  </el-form-item>
</el-form>
</template>
<script>
  export default {
    data() {
      return {
        form: {
          name: '',
          email: '',
          password: '',
        }
      }
    },
    methods: {
      onSubmit() {
        axios.post('/api/create',this.form)
        .then(response => {
          console.log(response);
          if (response.status == 200) {
            this.$notify({
              title: '成功',
              message: '添加用户成功',
              type: 'success'
            });
            this.resetForm();
            this.$router.push({name: 'list'})
          }
        });
      },
      resetForm(){
        this.form.name = '';
        this.form.email = '';
        this.form.password = '';
      }

    }
  }
</script>